from django.shortcuts import render
from rest_framework.generics import ListAPIView
from .models import SKU
from rest_framework.filters import OrderingFilter
from . import serializers
# Create your views here.

class SKUListView(ListAPIView):
    """
    商品列表
    """
    #指定序列化器
    serializer_class = serializers.SKUSerializer
    #指定过滤器
    filter_backends = (OrderingFilter,)
    #指定排序字段
    ordering_fields = ('create_time', 'price', 'sales')

    def get_queryset(self):
        category_id = self.kwargs.get('category_id')
        return SKU.objects.filter(category_id=category_id,is_launched=True)
